//-----------------------------------------------------------------------------
// Copyright (c) 2011 David Waby
// Initially created on 14/11/2011
//-----------------------------------------------------------------------------

#include "Global.h"
#include "Inventory.h"
#include "InventoryContainer.h"

//-----------------------------------------------------------------------------
Inventory::Inventory()
{
	int counter = 0;
	for (counter = 0; counter < INVENTORY_MAX_CONTAINERS; ++counter)
		m_containers[counter] = NULL;

	for (counter = 0; counter < EquipableSlot::Noof; ++counter)
		m_equipped[counter] = NULL;
} 

//-----------------------------------------------------------------------------
Inventory::~Inventory()
{
} 

//-----------------------------------------------------------------------------
bool Inventory::AddContainerToContainerSlot(InventoryContainer * i_container, int const i_containerSlot)
{
	if (m_containers[i_containerSlot] == NULL)
	{
		m_containers[i_containerSlot] = i_container;
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
bool Inventory::RemoveContainerFromContainerSlot(int const i_containerSlot)
{
	if (m_containers[i_containerSlot] && m_containers[i_containerSlot]->IsContainerEmpty())
	{
		m_containers[i_containerSlot] = NULL;
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
bool Inventory::AddInventoryItemToContainer(InventoryItem * i_item, int const i_containerSlot)
{
	if (m_containers[i_containerSlot])
	{
		return m_containers[i_containerSlot]->AddInventoryItemToContainer(i_item);
	}

	return false;
}

//-----------------------------------------------------------------------------
bool Inventory::RemoveInventoryItemFromContainer(InventoryItem * i_item, int const i_containerSlot)
{
	if (m_containers[i_containerSlot])
	{
		return m_containers[i_containerSlot]->RemoveInventoryItemFromContainer(i_item);
	}

	return false;
}

//-----------------------------------------------------------------------------
bool Inventory::EquipInventoryItem(InventoryItem * i_item)
{
	EquipableSlot::Enum const slot = i_item->GetEquipableSlot();
	if ((slot > EquipableSlot::None)&&(m_equipped[slot]==NULL))
	{
		m_equipped[slot] = i_item;
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
bool Inventory::UnEquipInventoryItem(InventoryItem * i_item)
{
	for (int counter = 0; counter < EquipableSlot::Noof; ++counter)
	{
		if (m_equipped[counter] == i_item)
		{
			m_equipped[counter] = NULL;
			return true;
		}
	}
		
	return false;
}